package Day2025_02_19;

public class LeetCode1004 {
    public static int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int maxLen = 0;
        int[] hash = new int[2];
        for (int left = 0, right = 0; right < n; right++) {
            hash[nums[right]]++;
            while (hash[0] > k) hash[nums[left++]]--;
            maxLen = Math.max(right - left + 1, maxLen);
        }
        return maxLen;
    }

    public static void main(String[] args) {
        int[] nums = {1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0};
        System.out.println(longestOnes(nums, 2));
    }
}
